//
//  TitleCell.m
//  MoneyIndividual
//
//  Created by Le Anh Tai on 1/5/14.
//  Copyright (c) 2014 Le Anh Tai. All rights reserved.
//

#import "TitleCell.h"

@implementation TitleCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self initializeTitle];
        [self initializeLine];
    }
    
    return self;
}

- (void)initializeTitle
{
    _titleLabel = [UILabel newNormalLabel];
    [_subView addSubview:_titleLabel];
}

- (void)initializeLine
{
    _lineTopView = [[UIView alloc] init];
    _lineTopView.backgroundColor = COLOR_GRAY_LIGHT;
    [self.contentView addSubview:_lineTopView];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    if (selected)
    {
        _titleLabel.textColor = COLOR_WHITE_PURE;
    }
    else
    {
        _titleLabel.textColor = COLOR_BLACK_PURE;
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _lineTopView.frame = RECT(0, self.contentView.height - 1, self.contentView.width, 1);
    
    _subView.frame = RECT(0, 0, self.contentView.width, self.contentView.height - _lineTopView.height);
    
    _titleLabel.frame = RECT(PADDING, 0, _subView.width/3, _subView.height);
    CGSize expectedTitleSize = [_titleLabel.text sizeWithFont:_titleLabel.font
                                            constrainedToSize:_titleLabel.frame.size
                                                lineBreakMode:_titleLabel.lineBreakMode];
    _titleLabel.width = expectedTitleSize.width;    
}


@end
